<template>
  <div class="home">
    <el-row class="h-per-100">
      <el-col :span="3" class="h-per-100">
        <div class="home-tab">
          <div
            v-for="(item, index) in echartsType"
            :key="item.id"
            :class="{ tabActive: tabActive === item.id }"
            class="home-tab-item flex_content_left flex_items_center"
            @click="handleTab(item)"
          >
            <div class="home-tab-item-icon mr-5">
              <i :class="item.icon" class="iconfont"></i>
            </div>
            <div class="home-tab-item-name">{{ item.name }}</div>
          </div>
        </div>
      </el-col>
      <el-col :span="21" class="h-per-100">
        <div class="home-main main-pdt">
          <div
            v-for="(item, index) in echratsList"
            :key="index"
            class="home-main-cont"
          >
            <div style="width: 100%;" class="title">{{item.name}}</div>
            <div class="home-list">
              <div
                  v-for="(childItem, childIndex) in item.children"
                  :key="childIndex"
                  class="home-list-item"
                  @click="handleItem(childItem)"
              >
                <div class="home-list-item-img">
                  <img :src="childItem.imageUrl" alt="" />
                </div>
                <div class="home-list-item-title">{{ childItem.name }}</div>
              </div>
            </div>

          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { data, echartsType } from "@/utils/data";

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "home1",
  data() {
    return {
      msg: 0,
      echartsType: echartsType,
      //左侧tab选中
      tabActive: 1,
      echratsList: {},
    };
  },
  created() {
    this.setData();
  },
  methods: {
    /**
     * 跳转详情
     * @param {Object} row - echarts图详情
     * @param {Number} row.id - echarts图ID
     */
    handleItem(row) {
      this.$router.push({ path: "/detail", query: { id: row.id } });
    },
    /**
     * 格式化数据
     */
    setData() {
      this.echratsList = JSON.parse(JSON.stringify(echartsType));
      data.forEach((item) => {
        let parent = this.echratsList.find((items) => items.id === item.typeId);
        if (parent) {
          if (!parent.children) {
            this.$set(parent, "children", []);
          }
          parent.children.push(item);
        }
      });
    },
    /**
     * 左侧tab切换
     * @param {Object} row - echart图类型
     * @param {Number} row.id - echart图类型ID
     * @param {Number} row.name - echart图类型名称
     */
    handleTab(row) {
      this.tabActive = row.id;
    },
  },
};
</script>

<style lang="scss" scoped>
.home {
  height: 100%;
  background-color: #f3f4fa;

  &-tab {
    position: sticky;
    left: 0;
    top: 0;
    float: left;
    height: calc(100%);
    width: 100%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    background-color: #fff;

    &-item {
      height: 25px;
      padding: 10px 0 10px 20px;
      display: block;
      text-decoration: none;
      color: #6e7079;
      cursor: pointer;
      &-name {
        display: inline-block;
        position: relative;
        vertical-align: middle;
        margin-left: 10px;
        color: #6e7079;
      }

      &-icon {
        i {
          color: #5067a2;
        }
      }
    }

    &-item:hover {
      border-right: 4px solid #5470c6;
    }

    .tabActive {
      background-color: #5470c6;
      color: #fff;

      i {
        color: #fff;
      }

      .home-tab-item-name {
        color: #fff;
      }
    }
  }
  &-main {
    height: 100%;
    overflow-y: auto;
  }
  .title{
    text-align: left;
    margin-bottom: 20px;
    padding-left: 20px;
    box-sizing: border-box;
    font-size: 20px;
  }
  &-list {
    height: auto;
    background-color: #f3f4fa;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    grid-column-gap: 0px;
    grid-row-gap: 0px;
    &-item {
      min-width: 200px;
      cursor: pointer;
      height: 300px;
      margin-left: 20px;
      &-img {
        overflow: hidden;
        img {
          max-width: 100%;
          object-fit: cover;
          transition: all 0.3s;
        }
      }
      &-title {
        text-align: left;
      }
    }
    &-item:hover {
      .home-list-item-img {
        img {
          transform: scale(1.1);
        }
      }
    }
  }
}
</style>
